#include<bits/stdc++.h>
using namespace std;
int n,m,fa[20010],l,r,a[20010],ans;
bool flg[20010],flg1[20010];
int main(){
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	scanf("%d%d",&n,&m);
	if(n>20000){
		while(m--){
			scanf("%d%d",&l,&r);
			printf("%d\n",r-l+1);
		}
		return 0;
	}
	for(int i=2;i<=n;i++)
		scanf("%d",&fa[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	while(m--){
		memset(flg,0,sizeof(flg)),memset(flg1,0,sizeof(flg1));
		ans=0;
		scanf("%d%d",&l,&r);
		for(int i=l;i<=r;i++){
			flg[a[i]]=1;
			int now=a[i];
			while(now!=1&&!flg1[now]) flg1[now]=1,now=fa[now];
			if(flg1[now]) flg[now]=1;
			flg1[now]=1;
		}
		for(int i=1;i<=n;i++)
			ans+=flg[i];
		printf("%d\n",ans);
	}
	return 0;
}
